package au.edu.educationau.opensource.dsm.worker;

import au.edu.educationau.opensource.dsm.DeusExMachina;

public abstract class AbstractSpellCheckTask  implements SpellCheckTask {
	public long token = 0;
	public String words = "";
	public long timeTaken = 0;
	public boolean finished = false;
	
	public AbstractSpellCheckTask() {
		super();
	}

	public long getTimeTaken() {
		return timeTaken;
	}

	public void terminate() {
		// let it go. ;)
	}

	public boolean isFinished() {
		return finished;
	}

	/**
	 * Checks the spelling and if there are updated terms, updates the corrected
	 * terms field in the Search Result Set
	 */
	public void run() {
		long time1 = System.currentTimeMillis();
		if (null != words) {
			String proposal = checkSpelling();
			if (proposal != null) {
				DeusExMachina._SearchResultService().updateCorrectedTerms(token, proposal);
			}
		}
		finished = true;
		long time2 = System.currentTimeMillis();
		this.timeTaken = time2 - time1;
	}

	protected abstract String checkSpelling();

}